package com.chengzhi.disruptor.heigh;

import com.lmax.disruptor.EventTranslator;
import com.lmax.disruptor.dsl.Disruptor;

import java.math.BigDecimal;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;

public class TradePublisher implements Runnable {
    private Disruptor<Trade> disruptor;
    private CountDownLatch latch;

    public TradePublisher(Disruptor<Trade> disruptor, CountDownLatch latch) {
        this.disruptor = disruptor;
        this.latch = latch;
    }

    @Override
    public void run() {
        for (int i = 0; i < 1; i++) {
            int finalI = i;
            this.disruptor.publishEvent(new EventTranslator<Trade>() {
                @Override
                public void translateTo(Trade event, long sequence) {
                    this.generateTrade(event);
                }

                private void generateTrade(Trade event) {
                    event.setId(String.valueOf(finalI));
                }
            });
        }
        latch.countDown();
    }
}

